<?php 

class suipaiModel extends appModel
{
	
	
	public function ordering($val,$id)
	{
		$result = array('error' => 0, 'content' => '编辑成功');
		$sql = "UPDATE ".$this->table('picture')." SET praise='$val' WHERE id='".$id."'";
		$res = $this->query($sql);
		if(!res)
		{
			$result['error'] = 1;
			$result['content'] = '编辑失败';
		}
		return $result;
	}
	
	public function get_list($sort, $page, $limit = 10)
	{
		$where = "  where 1=1 ";
		if(!empty($sort['c']))
		{
			$dotime1 = strtotime($sort['c']);
			
			$where .=" AND created >=".$dotime1;
		}
		
		if(!empty($sort['k']))
		{
			$dotime2 = strtotime($sort['k']);
				
			$where .=" AND created <=".$dotime2;
		}
		
		$listPage = array('data' => '', 'pageLink' => '');
		
		$sql = "SELECT p1.*,p2.nickname,p2.openid FROM ".$this->table('suipai')." as p1 ".
				"LEFT JOIN ".$this->table('wxusers')." as p2 on p1.wxid = p2.wxid ".
				$where." ORDER BY sp_id DESC";
		
		$result = $this->show_page($sql, $page, $limit);
		$listPage['pagelink'] = $result['page'];
		$listPage['data'] = $result['result'];
		if($result['result'])
		foreach ($result['result'] as $k => $v)
		{
			$v['pic'] = str_replace('["',"",$v['pic']);
			$v['pic'] = str_replace('"]',"",$v['pic']);
			$listPage['data'][$k]['pic'] = explode('","',$v['pic']);
			
		}
		
		return $listPage;
		
	}
	
	
	public function get_pic_list($sort, $page, $limit = 10)
	{
		$where = "  where 1=1 ";
		if(!empty($sort['c']))
		{
			$dotime1 = strtotime($sort['c']);
				
			$where .=" AND created >=".$dotime1;
		}
	
		if(!empty($sort['k']))
		{
			$dotime2 = strtotime($sort['k']);
	
			$where .=" AND created <=".$dotime2;
		}
	
		$listPage = array('data' => '', 'pageLink' => '');
	
		$sql = "SELECT p1.*,p2.nickname,p2.openid FROM ".$this->table('picture')." as p1 ".
				"LEFT JOIN ".$this->table('wxusers')." as p2 on p1.wxid = p2.wxid ".
				$where." ORDER BY praise desc ,created DESC";
	
		$result = $this->show_page($sql, $page, $limit);
		$listPage['pagelink'] = $result['page'];
		$listPage['data'] = $result['result'];
		
		return $listPage;
	
	}
	
	
	
	function del_sp($id,$table)
	{
		$result=array('error'=>0,'content'=>'删除成功');
		if($id)
		{
	
			$sql="DELETE FROM ".$this->table($table)." WHERE  sp_id='".$id."'";
	
			$res=$this->query($sql);
	
			if(!$res)
			{
				$result['error']=1;
				$result['content']='删除失败';
			}
	
	
		}
		return $result;
	
	
	}
	
	function del_pic($id)
	{
		$result=array('error'=>0,'content'=>'删除成功');
		if($id)
		{
	
			$sql="DELETE FROM ".$this->table("picture")." WHERE  id='".$id."'";
	
			$res=$this->query($sql);
	
			if(!$res)
			{
				$result['error']=1;
				$result['content']='删除失败';
			}
	
	
		}
		return $result;
	
	
	}
	
	function del_vote($id,$table)
	{
		$result=array('error'=>0,'content'=>'删除成功');
		if($id)
		{
	
			$sql="DELETE FROM ".$this->table($table)." WHERE  id='".$id."'";
	
			$res=$this->query($sql);
	
			if(!$res)
			{
				$result['error']=1;
				$result['content']='删除失败';
			}
	
	
		}
		return $result;
	
	
	}
}

?>